package com.itboye.jinpuyiyuan.activity.me;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.base.BaseActivity;
import com.itboye.jinpuyiyuan.presenter.BranchAddressPresenter;
import com.itboye.jinpuyiyuan.utils.sputil.Const;
import com.itboye.jinpuyiyuan.utils.sputil.SPUtils;
import com.itboye.jinpuyiyuan.utils.volley.ResultEntity;
import com.itboye.jinpuyiyuan.widget.loadingutil.MAlert;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by Administrator on 2018/2/9 0009.
 */

public class ResetPasswordActivity extends BaseActivity implements Observer {

    //title

    private ImageView leftImg,rightImg;
    private TextView leftTv,tvTitle;
    private RelativeLayout rlLeft,toobar,include_layout;

    private EditText oldPasswordEt,etResetPassword,etVertifyPassword;
    private TextView tvSure;
    private BranchAddressPresenter presenter;
    private String uid;
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_resetpassword);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.TRANSPARENT);
            include_layout.setBackgroundColor(Color.TRANSPARENT);
        }
        tvTitle.setText("忘记密码");
        presenter=new BranchAddressPresenter(this);
        uid= (String) SPUtils.get(getApplication(),null, Const.UID,"");
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){

            case R.id.rlLeft:
            case R.id.leftImg:

                this.finish();
                break;

            case R.id.tvSure:
                if (oldPasswordEt.getText().toString()==null||oldPasswordEt.getText().toString().equals("")
                        ||etResetPassword.getText().toString().equals("")||etResetPassword.getText().toString().equals("")
                        ||etVertifyPassword.getText().toString()==null||etVertifyPassword.getText().toString().equals("")) {
                    MAlert.alert("请填写完整信息");
                }else if (!etResetPassword.getText().toString().equals(etVertifyPassword.getText().toString())){
                    MAlert.alert("两次密码不一致");
                }else {
                    presenter.resetPassword(uid,oldPasswordEt.getText().toString(),etResetPassword.getText().toString());
                }

                break;
        }
    }

    @Override
    public void update(Observable o, Object arg) {

        ResultEntity resultEntity = handlerError(arg);

        if (resultEntity.getEventType()== BranchAddressPresenter.By_UserAccount_updatePwdByOldPwd_success){
//            MAlert.alert("密码修改成功", Gravity.CENTER);

        }else if (resultEntity.getEventType()== BranchAddressPresenter.By_UserAccount_updatePwdByOldPwd_fail){


        }
    }
}
